package com.fzt.framework.user;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author 非洲铜
 * @since 2022-12-08
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserDetail implements UserDetails {
    private static final long serialVersionUID = 1L;

    private Long    id;
    private String  username;
    private String  password;
    private String  realName;
    private String  avatar;
    private Integer gender;
    private String  email;
    private String  mobile;
    private Long    orgId;
    private Integer status;
    private Integer superAdmin;

    /**
     * 帐户是否过期
     */
    private boolean isAccountNonExpired     = true;
    /**
     * 帐户是否被锁定
     */
    private boolean isAccountNonLocked      = true;
    /**
     * 密码是否过期
     */
    private boolean isCredentialsNonExpired = true;
    /**
     * 帐户是否可用
     */
    private boolean isEnabled               = true;

    /**
     * 拥有权限集合
     */
    private Collection<? extends GrantedAuthority> authorities;

    /**
     * 数据权限范围
     * <p>
     * null：表示全部数据权限
     */
    private List<Long> dataScopeList;

    /**
     * todo 忽略了 authority 的反序列化
     */
    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.authorities;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return this.isAccountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.isAccountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return this.isCredentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }
}
